home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 27 / Mac Magazin and MacEasy Magazine CD - Issue 27.iso / Grafik & Text / Sans-Faute⁄Grammaire ƒ / Adaptateurs / Sources des scripts (anglais) / Vérification QuarkXPress® < prev    next >
Text File  |  1996-02-20  |  4KB  |  100 lines

  1. set kMaxStorySize to 10000 -- max number of characters of a story for checking it in one time
  2. set kMaxCheckingSFG to 32000 -- max number of characters that Sans-Faute/Grammaire can check
  3. set knbParagraphMaxToCheck to 25 -- max number of paragraphs sent to Sans-Faute/Grammaire
  4.  
  5. tell application "QuarkXPress®"
  6.     set FrontDocPresent to exists front document
  7. end tell
  8.  
  9. if FrontDocPresent then
  10.     
  11.     tell application "QuarkXPress®"
  12.         set nbStory to count stories of front document
  13.     end tell
  14.     
  15.     -- loop on each story
  16.     repeat with storyIdx from 1 to nbStory
  17.         
  18.         tell application "QuarkXPress®"
  19.             set storySize to count character of story storyIdx of front document
  20.         end tell
  21.         
  22.         if storySize > 0 then -- do something only for non null stories
  23.             if storySize > kMaxStorySize then -- big story -> split into bunch of paragraphs
  24.                 set endParagraphIdx to 0
  25.                 tell application "QuarkXPress®"
  26.                     set nbParagraph to count paragraph of story storyIdx of front document
  27.                 end tell
  28.                 repeat while endParagraphIdx < nbParagraph
  29.                     -- try to collect a maximum of paragraphs
  30.                     set paragraphIdx to endParagraphIdx + 1
  31.                     tell application "QuarkXPress®"
  32.                         set paragraphSize to count character of paragraph paragraphIdx of story storyIdx of front document
  33.                     end tell
  34.                     if paragraphSize > kMaxCheckingSFG then
  35.                         display dialog "Le paragraphe " & paragraphIdx & " du bloc " & storyIdx & " dépasse 32000 caractères. Sans-Faute/Grammaire ne peut pas le vérifier !"
  36.                     end if
  37.                     repeat while (paragraphIdx ≤ nbParagraph) and (paragraphSize > kMaxCheckingSFG)
  38.                         set paragraphIdx to paragraphIdx + 1
  39.                         if paragraphIdx ≤ nbParagraph then
  40.                             tell application "QuarkXPress®"
  41.                                 set paragraphSize to count character of paragraph paragraphIdx of story storyIdx of front document
  42.                             end tell
  43.                             if paragraphSize > kMaxCheckingSFG then
  44.                                 display dialog "Le paragraphe " & paragraphIdx & " du bloc " & storyIdx & " dépasse 32000 caractères. Sans-Faute/Grammaire ne peut pas le vérifier !"
  45.                             end if
  46.                         end if
  47.                     end repeat
  48.                     set startParagraphIdx to paragraphIdx
  49.                     
  50.                     set bunchSize to 0
  51.                     set nbparagraphBunch to 0
  52.                     set objToCheck to {}
  53.                     repeat while (paragraphIdx ≤ nbParagraph) and (nbparagraphBunch < knbParagraphMaxToCheck) and (bunchSize + paragraphSize ≤ kMaxStorySize)
  54.                         --   (paragraphSize ≤ kMaxCheckingSFG) is implicit
  55.                         set bunchSize to bunchSize + paragraphSize
  56.                         if paragraphSize > 0 then
  57.                             set objToCheck to objToCheck & {a reference to the text of the paragraph paragraphIdx of text flow storyIdx of front document}
  58.                             set nbparagraphBunch to nbparagraphBunch + 1
  59.                         end if
  60.                         
  61.                         set paragraphIdx to paragraphIdx + 1
  62.                         if paragraphIdx ≤ nbParagraph then
  63.                             tell application "QuarkXPress®"
  64.                                 set paragraphSize to count character of paragraph paragraphIdx of story storyIdx of front document
  65.                             end tell
  66.                         end if
  67.                     end repeat
  68.                     
  69.                     if (bunchSize = 0) and (paragraphIdx ≤ nbParagraph) and (paragraphSize ≤ kMaxCheckingSFG) then
  70.                         -- kMaxStorySize <paragraphSize ≤ kMaxCheckingSFG
  71.                         set objToCheck to objToCheck & {a reference to the text of the paragraph paragraphIdx of text flow storyIdx of front document}
  72.                         set endParagraphIdx to paragraphIdx
  73.                         set bunchSize to paragraphSize
  74.                     else
  75.                         set endParagraphIdx to paragraphIdx - 1
  76.                     end if
  77.                     
  78.                     if bunchSize > 0 then -- cas be zero if the end of the story contains only paragraphs > 32000
  79.                         -- tell Sans-Faute/Grammaire to check the content of the list of  references and made changes in Application XPress
  80.                         tell application "Sans-Faute/Grammaire 2"
  81.                             Checking objToCheck ClientAddress Application "QuarkXPress®"
  82.                         end tell
  83.                     end if
  84.                 end repeat
  85.             else
  86.                 -- small story -> it fits
  87.                 -- prepare an object reference to entire story
  88.                 set objToCheck to (a reference to the text of the text flow storyIdx of front document)
  89.                 -- tell Sans-Faute/Grammaire to check the content of the reference and made changes in Application XPress
  90.                 tell application "Sans-Faute/Grammaire 2"
  91.                     Checking {objToCheck} ClientAddress Application "QuarkXPress®"
  92.                 end tell
  93.             end if
  94.         end if
  95.         
  96.     end repeat
  97. else
  98.     display dialog "Aucun document n'est ouvert dans QuarkXPress® !"
  99. end if
  100.